package datebase;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class WorkclassDaoIplm implements WorkclassDao {
	@Override
	public Workclass serach(Connection con,String first_class,String second_class) throws SQLException {
			Workclass wc = null;
			if (con == null) {
	            throw new SQLException("数据库连接不能为null");
	        }
			String sql = "select work_class_id from Workclass where first_class=? and second_class=?";
			PreparedStatement ps = con.prepareStatement(sql);
			ps.setString(1, first_class);
			ps.setString(2, second_class);
			ResultSet rs = ps.executeQuery();
			 if (rs.next()) {
	                // 只取第一行，或者根据业务需求处理多行
	                wc = new Workclass(rs.getInt("work_class_id"), first_class, second_class);
	                System.out.println(wc.getWork_class_id()+":"+wc.getFirst_class()+":"+wc.getSecond_class());
	            } else {
	                // 明确返回null或抛出异常，避免歧义
	                System.out.println("未查询到结果");
	                // 或者：throw new SQLException("未找到对应的工作类别");
	            }
			 return wc;
	}
}
